Ext.define('PJ.view.trainingmanagement.Upload', {
    extend: 'AM.default.DefaultWindowForm',
    
    width: 400,
    autoHeight: true,
    
    initComponent: function(){
    	var me = this;
        this.items = [{
        	xtype: "container",
        	layout: "column",
        	items:[{
            	xtype:"filefield",
            	fieldLabel: "请选择文件",
            	margin: '5 0 0 0',
            	labelWidth: 75,
				labelAlign:'right',
            	columnWidth: .98,
            	name: "aicc",
                emptyText:"请选择文件",
                buttonText: '',
                buttonConfig: {
                    iconCls: 'updateIco'
                },
                validator: function(value){
                	var arr = value.split('.');
                	if(arr[arr.length-1] == 'xls' || arr[arr.length-1] == 'xlsx' || arr[arr.length-1] == 'pdf' || arr[arr.length-1] == 'doc' || arr[arr.length-1] == 'docx' || arr[arr.length-1] == 'rar' || arr[arr.length-1] == 'zip'){
                		return true;
                	}else {
                		return '您上传的文件格式不正确！';
                	}
                }
            }, {
                xtype: 'label',
                html: '导入文件格式为.xls .xlsx .pdf .doc .docx .rar .zip',
                style: 'color:red;',
                margin: '5 0 0 45',
                columnWidth: 1
            }]
        }];
        this.buttons = [{
        	text: '确定',
        	scope: this,
        	handler: function(button,event){
        		var win = button.up("window");
        		win.sub();
        	}
        },{
            text: '关闭',
            scope: this,
            handler: function(button, event){
				button.up('window').close();
            }
        }];
        this.callParent(arguments);
    },
    sub: function(){
    	var win = this;
    	var form = win.down('form');
    	var baseForm = form.getForm();
    	if (!baseForm.isValid()) {
    		return;
    	}
		win.submit({
			url: win.grid.store.importUrl,
			params: {
				classId: win.classId
			},
    		success: function(f, action){
    			if (action.result.success) {
    				Ext.Msg.alert('提示', '操作成功！', function(){
    					win.grid.getStore().load();
        				win.close();
    				});
    			}else{
    				Ext.Msg.alert('提示', action.result.msg, function(){
    					win.close();
    				});
    			}
    		},
    		failure: function(f, action){
    			if (action.result) {
    				Ext.Msg.alert('提示', action.result.msg, function(){
    					win.close();
    				});
    			}
    			else {
    				Ext.Msg.alert('提示', '操作失败！', function(){
    					win.close();
    				});
    			}
    		}
    	});
    },
    listeners: {
    	close: function(){
    		this.grid.store.load();
    	}
    }
});
